// Copyright Epic Games, Inc. All Rights Reserved.

#include "CustomSettings/LyraSettingValueDiscrete_PerfStat.h"
#include "EditCondition/WhenPlayingAsPrimaryPlayer.h"
#include "GameSettingCollection.h"
#include "GameSettingValueDiscreteDynamic.h"
#include "HAL/IConsoleManager.h"
#include "LyraGameSettingRegistry.h"
#include "LyraSettingsLocal.h"
#include "Performance/LyraPerformanceStatTypes.h"
#include "Player/LyraLocalPlayer.h"
#include "RHI.h"

class ULyraLocalPlayer;

#define LOCTEXT_NAMESPACE "Lyra"

// 控制台变量：延迟标记是否需要NVIDIA
static TAutoConsoleVariable<bool> CVarLatencyMarkersRequireNVIDIA(TEXT("Lyra.Settings.LatencyMarkersRequireNVIDIA"),
	true, // 默认值
	TEXT("If true, then only allow latency markers to be enabled on NVIDIA hardware"), // 描述：如果为true，则只允许在NVIDIA硬件上启用延迟标记
	ECVF_Default);

// 检查当前平台是否支持延迟统计的游戏设置编辑条件类
class FGameSettingEditCondition_LatencyStatsSupported final : public FGameSettingEditCondition
{
public:
	FGameSettingEditCondition_LatencyStatsSupported() = default; // 默认构造函数

	/**
	 * 收集编辑状态
	 * @param InLocalPlayer 本地玩家
	 * @param InOutEditState 输入输出编辑状态
	 */
	virtual void GatherEditState(const ULocalPlayer * InLocalPlayer, FGameSettingEditableState & InOutEditState) const override
	{
		if (!ULyraSettingsLocal::DoesPlatformSupportLatencyTrackingStats()) // 如果平台不支持延迟跟踪统计
		{
			InOutEditState.Disable(LOCTEXT("PlatformDoesNotSupportLatencyStates", "Latency performance stats are not supported on this device")); // 禁用设置
		}
	}
};

// 检查延迟统计当前是否启用并监听更改以正确更新编辑条件状态的游戏设置编辑条件类
class FGameSettingEditCondition_LatencyStatsCurrentlyEnabled final : public FGameSettingEditCondition
{
public:
	FGameSettingEditCondition_LatencyStatsCurrentlyEnabled() = default; // 默认构造函数

	virtual ~FGameSettingEditCondition_LatencyStatsCurrentlyEnabled() override // 析构函数
	{
		if (!SettingChangedDelegate.IsValid()) // 如果设置更改委托无效
		{
			return; // 直接返回
		}
		
		ULyraSettingsLocal* Settings = ULyraSettingsLocal::Get(); // 获取Lyra本地设置
		if (!Settings) // 如果设置不存在
		{
			return; // 直接返回
		}
		
		Settings->OnLatencyStatIndicatorSettingsChangedEvent().Remove(SettingChangedDelegate); // 移除设置更改委托
	}

private:
	
	/**
	 * 初始化编辑条件
	 * @param InLocalPlayer 本地玩家
	 */
	virtual void Initialize(const ULocalPlayer* InLocalPlayer) override
	{
		// 绑定到设置更新时的事件，以便我们可以广播需要重新评估
		ULyraSettingsLocal* Settings = ULyraSettingsLocal::Get(); // 获取Lyra本地设置
		if (!Settings) // 如果设置不存在
		{
			return; // 直接返回
		}

		SettingChangedDelegate = Settings->OnLatencyStatIndicatorSettingsChangedEvent().AddSP(this->AsShared(), &FGameSettingEditCondition_LatencyStatsCurrentlyEnabled::BroadcastEditConditionChanged); // 添加设置更改委托
	}
	
	/**
	 * 收集编辑状态
	 * @param InLocalPlayer 本地玩家
	 * @param InOutEditState 输入输出编辑状态
	 */
	virtual void GatherEditState(const ULocalPlayer * InLocalPlayer, FGameSettingEditableState & InOutEditState) const override
	{
		const ULyraSettingsLocal* Settings = ULyraSettingsLocal::Get(); // 获取Lyra本地设置
		if (!Settings) // 如果设置不存在
		{
			return; // 直接返回
		}

		if (!Settings->GetEnableLatencyTrackingStats()) // 如果未启用延迟跟踪统计
		{
			InOutEditState.Disable(LOCTEXT("LatencyMarkerRequireStatsEnabled", "Latency Tracking Stats must be enabled to use this.")); // 禁用设置
		}	
	}
	
	FDelegateHandle SettingChangedDelegate; // 设置更改委托句柄
};

// 检查当前平台是否支持延迟标记的游戏设置编辑条件类
class FGameSettingEditCondition_LatencyMarkersSupported final : public FGameSettingEditCondition
{
public:
	FGameSettingEditCondition_LatencyMarkersSupported() = default; // 默认构造函数

	/**
	 * 收集编辑状态
	 * @param InLocalPlayer 本地玩家
	 * @param InOutEditState 输入输出编辑状态
	 */
	virtual void GatherEditState(const ULocalPlayer * InLocalPlayer, FGameSettingEditableState & InOutEditState) const override
	{
		if (!ULyraSettingsLocal::DoesPlatformSupportLatencyMarkers()) // 如果平台不支持延迟标记
		{
			InOutEditState.Disable(LOCTEXT("PlatformDoesNotSupportLatencyMarkers", "Latency markers are not supported on this device")); // 禁用设置
		}

		// Lyra只使用"Reflex"插件来跟踪这些延迟统计，因此将这些设置限制为NVIDIA设备
		if (CVarLatencyMarkersRequireNVIDIA.GetValueOnAnyThread() && !IsRHIDeviceNVIDIA()) // 如果需要NVIDIA且不是NVIDIA设备
		{
			InOutEditState.Disable(LOCTEXT("InputLatencyMarkersRequiresNVIDIA", "Latency markers only work on NVIDIA devices.")); // 禁用设置
		}
	}
};

//////////////////////////////////////////////////////////////////////

/**
 * 添加性能统计页面
 * @param PerfStatsOuterCategory 性能统计外部类别
 * @param InLocalPlayer 本地玩家
 */
void ULyraGameSettingRegistry::AddPerformanceStatPage(UGameSettingCollection* PerfStatsOuterCategory, ULyraLocalPlayer* InLocalPlayer)
{
	//----------------------------------------------------------------------------------
	{
		static_assert((int32)ELyraDisplayablePerformanceStat::Count == 18, "Consider updating this function to deal with new performance stats"); // 静态断言：如果性能统计数量改变，考虑更新此函数

		UGameSettingCollectionPage* StatsPage = NewObject<UGameSettingCollectionPage>(); // 创建统计设置页面
		StatsPage->SetDevName(TEXT("PerfStatsPage")); // 设置开发名称
		StatsPage->SetDisplayName(LOCTEXT("PerfStatsPage_Name", "Performance Stats")); // 设置显示名称
		StatsPage->SetDescriptionRichText(LOCTEXT("PerfStatsPage_Description", "Configure the display of performance statistics.")); // 设置描述富文本
		StatsPage->SetNavigationText(LOCTEXT("PerfStatsPage_Navigation", "Edit")); // 设置导航文本

		StatsPage->AddEditCondition(FWhenPlayingAsPrimaryPlayer::Get()); // 添加编辑条件

		PerfStatsOuterCategory->AddSetting(StatsPage); // 添加到性能统计外部类别

		// 性能统计
		////////////////////////////////////////////////////////////////////////////////////
		{
			UGameSettingCollection* StatCategory_Performance = NewObject<UGameSettingCollection>(); // 创建性能统计类别
			StatCategory_Performance->SetDevName(TEXT("StatCategory_Performance")); // 设置开发名称
			StatCategory_Performance->SetDisplayName(LOCTEXT("StatCategory_Performance_Name", "Performance")); // 设置显示名称
			StatsPage->AddSetting(StatCategory_Performance); // 添加到统计页面

			//----------------------------------------------------------------------------------
			{
				ULyraSettingValueDiscrete_PerfStat* Setting = NewObject<ULyraSettingValueDiscrete_PerfStat>(); // 创建性能统计离散值设置
				Setting->SetStat(ELyraDisplayablePerformanceStat::ClientFPS); // 设置统计类型：客户端FPS
				Setting->SetDisplayName(LOCTEXT("PerfStat_ClientFPS", "Client FPS")); // 设置显示名称
				Setting->SetDescriptionRichText(LOCTEXT("PerfStatDescription_ClientFPS", "Client frame rate (higher is better)")); // 设置描述富文本
				StatCategory_Performance->AddSetting(Setting); // 添加到性能统计类别
			}
			//----------------------------------------------------------------------------------
			{
				ULyraSettingValueDiscrete_PerfStat* Setting = NewObject<ULyraSettingValueDiscrete_PerfStat>(); // 创建性能统计离散值设置
				Setting->SetStat(ELyraDisplayablePerformanceStat::ServerFPS); // 设置统计类型：服务器FPS
				Setting->SetDisplayName(LOCTEXT("PerfStat_ServerFPS", "Server FPS")); // 设置显示名称
				Setting->SetDescriptionRichText(LOCTEXT("PerfStatDescription_ServerFPS", "Server frame rate")); // 设置描述富文本
				StatCategory_Performance->AddSetting(Setting); // 添加到性能统计类别
			}
			//----------------------------------------------------------------------------------
			{
				ULyraSettingValueDiscrete_PerfStat* Setting = NewObject<ULyraSettingValueDiscrete_PerfStat>(); // 创建性能统计离散值设置
				Setting->SetStat(ELyraDisplayablePerformanceStat::FrameTime); // 设置统计类型：帧时间
				Setting->SetDisplayName(LOCTEXT("PerfStat_FrameTime", "Frame Time")); // 设置显示名称
				Setting->SetDescriptionRichText(LOCTEXT("PerfStatDescription_FrameTime", "The total frame time.")); // 设置描述富文本
				StatCategory_Performance->AddSetting(Setting); // 添加到性能统计类别
			}
			//----------------------------------------------------------------------------------
			{
				ULyraSettingValueDiscrete_PerfStat* Setting = NewObject<ULyraSettingValueDiscrete_PerfStat>(); // 创建性能统计离散值设置
				Setting->SetStat(ELyraDisplayablePerformanceStat::IdleTime); // 设置统计类型：空闲时间
				Setting->SetDisplayName(LOCTEXT("PerfStat_IdleTime", "Idle Time")); // 设置显示名称
				Setting->SetDescriptionRichText(LOCTEXT("PerfStatDescription_IdleTime", "The amount of time spent waiting idle for frame pacing.")); // 设置描述富文本
				StatCategory_Performance->AddSetting(Setting); // 添加到性能统计类别
			}
			//----------------------------------------------------------------------------------
			{
				ULyraSettingValueDiscrete_PerfStat* Setting = NewObject<ULyraSettingValueDiscrete_PerfStat>(); // 创建性能统计离散值设置
				Setting->SetStat(ELyraDisplayablePerformanceStat::FrameTime_GameThread); // 设置统计类型：游戏线程帧时间
				Setting->SetDisplayName(LOCTEXT("PerfStat_FrameTime_GameThread", "CPU Game Time")); // 设置显示名称
				Setting->SetDescriptionRichText(LOCTEXT("PerfStatDescription_FrameTime_GameThread", "The amount of time spent on the main game thread.")); // 设置描述富文本
				StatCategory_Performance->AddSetting(Setting); // 添加到性能统计类别
			}
			//----------------------------------------------------------------------------------
			{
				ULyraSettingValueDiscrete_PerfStat* Setting = NewObject<ULyraSettingValueDiscrete_PerfStat>(); // 创建性能统计离散值设置
				Setting->SetStat(ELyraDisplayablePerformanceStat::FrameTime_RenderThread); // 设置统计类型：渲染线程帧时间
				Setting->SetDisplayName(LOCTEXT("PerfStat_FrameTime_RenderThread", "CPU Render Time")); // 设置显示名称
				Setting->SetDescriptionRichText(LOCTEXT("PerfStatDescription_FrameTime_RenderThread", "The amount of time spent on the rendering thread.")); // 设置描述富文本
				StatCategory_Performance->AddSetting(Setting); // 添加到性能统计类别
			}
			//----------------------------------------------------------------------------------
			{
				ULyraSettingValueDiscrete_PerfStat* Setting = NewObject<ULyraSettingValueDiscrete_PerfStat>(); // 创建性能统计离散值设置
				Setting->SetStat(ELyraDisplayablePerformanceStat::FrameTime_RHIThread); // 设置统计类型：RHI线程帧时间
				Setting->SetDisplayName(LOCTEXT("PerfStat_FrameTime_RHIThread", "CPU RHI Time")); // 设置显示名称
				Setting->SetDescriptionRichText(LOCTEXT("PerfStatDescription_FrameTime_RHIThread", "The amount of time spent on the Render Hardware Interface thread.")); // 设置描述富文本
				StatCategory_Performance->AddSetting(Setting); // 添加到性能统计类别
			}
			//----------------------------------------------------------------------------------
			{
				ULyraSettingValueDiscrete_PerfStat* Setting = NewObject<ULyraSettingValueDiscrete_PerfStat>(); // 创建性能统计离散值设置
				Setting->SetStat(ELyraDisplayablePerformanceStat::FrameTime_GPU); // 设置统计类型：GPU渲染时间
				Setting->SetDisplayName(LOCTEXT("PerfStat_FrameTime_GPU", "GPU Render Time")); // 设置显示名称
				Setting->SetDescriptionRichText(LOCTEXT("PerfStatDescription_FrameTime_GPU", "The amount of time spent on the GPU.")); // 设置描述富文本
				StatCategory_Performance->AddSetting(Setting); // 添加到性能统计类别
			}
			//----------------------------------------------------------------------------------
		}

		// 网络统计
		////////////////////////////////////////////////////////////////////////////////////
		{
			UGameSettingCollection* StatCategory_Network = NewObject<UGameSettingCollection>(); // 创建网络统计类别
			StatCategory_Network->SetDevName(TEXT("StatCategory_Network")); // 设置开发名称
			StatCategory_Network->SetDisplayName(LOCTEXT("StatCategory_Network_Name", "Network")); // 设置显示名称
			StatsPage->AddSetting(StatCategory_Network); // 添加到统计页面

			//----------------------------------------------------------------------------------
			{
				ULyraSettingValueDiscrete_PerfStat* Setting = NewObject<ULyraSettingValueDiscrete_PerfStat>(); // 创建性能统计离散值设置
				Setting->SetStat(ELyraDisplayablePerformanceStat::Ping); // 设置统计类型：Ping
				Setting->SetDisplayName(LOCTEXT("PerfStat_Ping", "Ping")); // 设置显示名称
				Setting->SetDescriptionRichText(LOCTEXT("PerfStatDescription_Ping", "The roundtrip latency of your connection to the server.")); // 设置描述富文本
				StatCategory_Network->AddSetting(Setting); // 添加到网络统计类别
			}
			//----------------------------------------------------------------------------------
			{
				ULyraSettingValueDiscrete_PerfStat* Setting = NewObject<ULyraSettingValueDiscrete_PerfStat>(); // 创建性能统计离散值设置
				Setting->SetStat(ELyraDisplayablePerformanceStat::PacketLoss_Incoming); // 设置统计类型：传入丢包率
				Setting->SetDisplayName(LOCTEXT("PerfStat_PacketLoss_Incoming", "Incoming Packet Loss")); // 设置显示名称
				Setting->SetDescriptionRichText(LOCTEXT("PerfStatDescription_PacketLoss_Incoming", "The percentage of incoming packets lost.")); // 设置描述富文本
				StatCategory_Network->AddSetting(Setting); // 添加到网络统计类别
			}
			//----------------------------------------------------------------------------------
			{
				ULyraSettingValueDiscrete_PerfStat* Setting = NewObject<ULyraSettingValueDiscrete_PerfStat>(); // 创建性能统计离散值设置
				Setting->SetStat(ELyraDisplayablePerformanceStat::PacketLoss_Outgoing); // 设置统计类型：传出丢包率
				Setting->SetDisplayName(LOCTEXT("PerfStat_PacketLoss_Outgoing", "Outgoing Packet Loss")); // 设置显示名称
				Setting->SetDescriptionRichText(LOCTEXT("PerfStatDescription_PacketLoss_Outgoing", "The percentage of outgoing packets lost.")); // 设置描述富文本
				StatCategory_Network->AddSetting(Setting); // 添加到网络统计类别
			}
			//----------------------------------------------------------------------------------
			{
				ULyraSettingValueDiscrete_PerfStat* Setting = NewObject<ULyraSettingValueDiscrete_PerfStat>(); // 创建性能统计离散值设置
				Setting->SetStat(ELyraDisplayablePerformanceStat::PacketRate_Incoming); // 设置统计类型：传入包率
				Setting->SetDisplayName(LOCTEXT("PerfStat_PacketRate_Incoming", "Incoming Packet Rate")); // 设置显示名称
				Setting->SetDescriptionRichText(LOCTEXT("PerfStatDescription_PacketRate_Incoming", "Rate of incoming packets (per second)")); // 设置描述富文本
				StatCategory_Network->AddSetting(Setting); // 添加到网络统计类别
			}
			//----------------------------------------------------------------------------------
			{
				ULyraSettingValueDiscrete_PerfStat* Setting = NewObject<ULyraSettingValueDiscrete_PerfStat>(); // 创建性能统计离散值设置
				Setting->SetStat(ELyraDisplayablePerformanceStat::PacketRate_Outgoing); // 设置统计类型：传出包率
				Setting->SetDisplayName(LOCTEXT("PerfStat_PacketRate_Outgoing", "Outgoing Packet Rate")); // 设置显示名称
				Setting->SetDescriptionRichText(LOCTEXT("PerfStatDescription_PacketRate_Outgoing", "Rate of outgoing packets (per second)")); // 设置描述富文本
				StatCategory_Network->AddSetting(Setting); // 添加到网络统计类别
			}
			//----------------------------------------------------------------------------------
			{
				ULyraSettingValueDiscrete_PerfStat* Setting = NewObject<ULyraSettingValueDiscrete_PerfStat>(); // 创建性能统计离散值设置
				Setting->SetStat(ELyraDisplayablePerformanceStat::PacketSize_Incoming); // 设置统计类型：传入包大小
				Setting->SetDisplayName(LOCTEXT("PerfStat_PacketSize_Incoming", "Incoming Packet Size")); // 设置显示名称
				Setting->SetDescriptionRichText(LOCTEXT("PerfStatDescription_PacketSize_Incoming", "The average size (in bytes) of packets recieved in the last second.")); // 设置描述富文本
				StatCategory_Network->AddSetting(Setting); // 添加到网络统计类别
			}
			//----------------------------------------------------------------------------------
			{
				ULyraSettingValueDiscrete_PerfStat* Setting = NewObject<ULyraSettingValueDiscrete_PerfStat>(); // 创建性能统计离散值设置
				Setting->SetStat(ELyraDisplayablePerformanceStat::PacketSize_Outgoing); // 设置统计类型：传出包大小
				Setting->SetDisplayName(LOCTEXT("PerfStat_PacketSize_Outgoing", "Outgoing Packet Size")); // 设置显示名称
				Setting->SetDescriptionRichText(LOCTEXT("PerfStatDescription_PacketSize_Outgoing", "The average size (in bytes) of packets sent in the last second.")); // 设置描述富文本
				StatCategory_Network->AddSetting(Setting); // 添加到网络统计类别
			}
			//----------------------------------------------------------------------------------
		}

		// 延迟统计
		////////////////////////////////////////////////////////////////////////////////////
		{
			UGameSettingCollection* StatCategory_Latency = NewObject<UGameSettingCollection>(); // 创建延迟统计类别
			StatCategory_Latency->SetDevName(TEXT("StatCategory_Latency")); // 设置开发名称
			StatCategory_Latency->SetDisplayName(LOCTEXT("StatCategory_Latency_Name", "Latency")); // 设置显示名称
			StatsPage->AddSetting(StatCategory_Latency); // 添加到统计页面

			//----------------------------------------------------------------------------------
			{
				UGameSettingValueDiscreteDynamic_Bool* Setting = NewObject<UGameSettingValueDiscreteDynamic_Bool>(); // 创建布尔离散值设置
				Setting->SetDevName(TEXT("InputLatencyTrackingStats")); // 设置开发名称
				Setting->SetDisplayName(LOCTEXT("InputLatencyTrackingStats_Name", "Enable Latency Tracking Stats")); // 设置显示名称
				Setting->SetDescriptionRichText(LOCTEXT("InputLatencyTrackingStats_Description", "Enabling Input Latency stat tracking")); // 设置描述富文本

				Setting->SetDynamicGetter(GET_LOCAL_SETTINGS_FUNCTION_PATH(GetEnableLatencyTrackingStats)); // 设置动态获取器
				Setting->SetDynamicSetter(GET_LOCAL_SETTINGS_FUNCTION_PATH(SetEnableLatencyTrackingStats)); // 设置动态设置器

				// 如果平台支持延迟跟踪统计，则设置默认值为true
				Setting->SetDefaultValue(ULyraSettingsLocal::DoesPlatformSupportLatencyTrackingStats()); // 设置默认值
				Setting->AddEditCondition(MakeShared<FGameSettingEditCondition_LatencyStatsSupported>()); // 添加编辑条件
				
				StatCategory_Latency->AddSetting(Setting); // 添加到延迟统计类别
			}
			//----------------------------------------------------------------------------------
			{
				UGameSettingValueDiscreteDynamic_Bool* Setting = NewObject<UGameSettingValueDiscreteDynamic_Bool>(); // 创建布尔离散值设置
				Setting->SetDevName(TEXT("InputLatencyMarkers")); // 设置开发名称
				Setting->SetDisplayName(LOCTEXT("InputLatencyMarkers_Name", "Enable Latency Markers")); // 设置显示名称
				Setting->SetDescriptionRichText(LOCTEXT("InputLatencyMarkers_Description", "Enabling Input Latency Markers to flash the screen")); // 设置描述富文本

				Setting->SetDynamicGetter(GET_LOCAL_SETTINGS_FUNCTION_PATH(GetEnableLatencyFlashIndicators)); // 设置动态获取器
				Setting->SetDynamicSetter(GET_LOCAL_SETTINGS_FUNCTION_PATH(SetEnableLatencyFlashIndicators)); // 设置动态设置器
				Setting->SetDefaultValue(false); // 设置默认值

				// 延迟标记需要统计被支持并启用
				Setting->AddEditCondition(MakeShared<FGameSettingEditCondition_LatencyStatsSupported>()); // 添加编辑条件
				Setting->AddEditCondition(MakeShared<FGameSettingEditCondition_LatencyStatsCurrentlyEnabled>()); // 添加编辑条件
				
				Setting->AddEditCondition(MakeShared<FGameSettingEditCondition_LatencyMarkersSupported>()); // 添加编辑条件

				StatCategory_Latency->AddSetting(Setting); // 添加到延迟统计类别
			}
			
			//----------------------------------------------------------------------------------
			{
				ULyraSettingValueDiscrete_PerfStat* Setting = NewObject<ULyraSettingValueDiscrete_PerfStat>(); // 创建性能统计离散值设置
				Setting->SetStat(ELyraDisplayablePerformanceStat::Latency_Total); // 设置统计类型：总游戏延迟
				Setting->SetDisplayName(LOCTEXT("PerfStat_Latency_Total", "Total Game Latency")); // 设置显示名称
				Setting->SetDescriptionRichText(LOCTEXT("PerfStatDescription_Latency_Total", "The total amount of latency")); // 设置描述富文本
				Setting->AddEditCondition(MakeShared<FGameSettingEditCondition_LatencyStatsSupported>()); // 添加编辑条件
				Setting->AddEditCondition(MakeShared<FGameSettingEditCondition_LatencyStatsCurrentlyEnabled>()); // 添加编辑条件
				StatCategory_Latency->AddSetting(Setting); // 添加到延迟统计类别
			}
			//----------------------------------------------------------------------------------
			{
				ULyraSettingValueDiscrete_PerfStat* Setting = NewObject<ULyraSettingValueDiscrete_PerfStat>(); // 创建性能统计离散值设置
				Setting->SetStat(ELyraDisplayablePerformanceStat::Latency_Game); // 设置统计类型：游戏延迟
				Setting->SetDisplayName(LOCTEXT("PerfStat_Latency_Game", "Game Latency")); // 设置显示名称
				Setting->SetDescriptionRichText(LOCTEXT("PerfStatDescription_Latency_Game", "Game simulation start to driver submission end")); // 设置描述富文本
				Setting->AddEditCondition(MakeShared<FGameSettingEditCondition_LatencyStatsSupported>()); // 添加编辑条件
				Setting->AddEditCondition(MakeShared<FGameSettingEditCondition_LatencyStatsCurrentlyEnabled>()); // 添加编辑条件
				StatCategory_Latency->AddSetting(Setting); // 添加到延迟统计类别
			}
			//----------------------------------------------------------------------------------
			{
				ULyraSettingValueDiscrete_PerfStat* Setting = NewObject<ULyraSettingValueDiscrete_PerfStat>(); // 创建性能统计离散值设置
				Setting->SetStat(ELyraDisplayablePerformanceStat::Latency_Render); // 设置统计类型：渲染延迟
				Setting->SetDisplayName(LOCTEXT("PerfStat_Latency_Render", "Render Latency")); // 设置显示名称
				Setting->SetDescriptionRichText(LOCTEXT("PerfStatDescription_Latency_Render", "OS render queue start to GPU render end")); // 设置描述富文本
				Setting->AddEditCondition(MakeShared<FGameSettingEditCondition_LatencyStatsSupported>()); // 添加编辑条件
				Setting->AddEditCondition(MakeShared<FGameSettingEditCondition_LatencyStatsCurrentlyEnabled>()); // 添加编辑条件
				StatCategory_Latency->AddSetting(Setting); // 添加到延迟统计类别
			}
		}
	}
}

#undef LOCTEXT_NAMESPACE